$(function(){
		//切换TAB页
		$(".etabs li").click(function(){ 
	        var index = $('.etabs li').index(this);
	        $(".etabs li").each(function(i,obj){
	            var flag = $(obj).children("span").attr('flag');
	            if(i!=index){
	                $(obj).children(".leftbg").removeClass("leftbg_select"); 
	                $(obj).children(".centerbg").removeClass("centerbg_select");
	                $(obj).children(".rightbg").removeClass("rightbg_select");
	                $(obj).children("span").removeClass(flag+"_select");
	                if(i==2){
	                	$("#fjDiv").panel('close'); 
	                }else{
	                	$(".panel-container > div").eq(i).css("display","none"); 
	                }
	            }else{
	                $(obj).children(".leftbg").addClass("leftbg_select");
	                $(obj).children(".centerbg").addClass("centerbg_select");
	                $(obj).children(".rightbg").addClass("rightbg_select");
	                $(obj).children("span").addClass(flag+"_select");
	                if(i==2){
	                	 $("#fjDiv").panel('open'); 
	                }else{
	                	$(".panel-container > div").eq(i).css("display","block"); 
	                }
	            }
	            
	            if(i==1){
	            	$("#replyContent").mCustomScrollbar("destroy");
	            	
	            	$("#replyContent").mCustomScrollbar({ 
	    				theme: "light-thick",
	    				scrollInertia:0,
	    				autoDraggerLength:true,
	    				scrollButtons:{
	    					enable:false
	    				}
	    			});
	            	
	            //	$("div.mCSB_dragger").css("height","200px");
	            }
	        });  
	        
	        
	        
//	        $("#ddContent").mCustomScrollbar("update");
	  }); 
//		$(window).load(function(){
//			 
//		});	  
//		
	    //初始化详细信息里的五角星
		var evaluate = $("#evaluate").val();
		
		$(".star-detail li").each(function(index,value){
			if(index+1>evaluate){
				$(this).removeClass("star-hover");
			}else{
				$(this).addClass("star-hover"); 
			}
		});
		
		//评分操作
		$(".star-control li").mouseover(function(){
			var indexS = $(this).attr("imgval");
			$(".star-control li").each(function(index,value){
				if(index+1>indexS){
					$(this).removeClass("star-hover");
				}else{
					$(this).addClass("star-hover"); 
				}
			});
		}).mouseout(function(){
			$(".star-control li").each(function(index,value){
				$(this).removeClass("star-hover"); 
			});  
		});
		
		
		$(".star-control li").click(function(){
				var indexS = $(this).attr("imgval");
				$(".star-control li").each(function(index,value){
					$(this).removeClass("star-hover");
					$(this).removeClass("star-on"); 
					if(index+1>indexS){
						//$(this).removeClass("star-hover");
					}else{
						$(this).addClass("star-on"); 
					}
				});
				$("#evaluateScore").val($(this).attr("imgval"));
		});
		
		
		
		
		
		
		initAttachment(); //初始化附件列表
		
		showGridList({rows:4,knowledgeId:$("#knowledgeId").val()});  //显示回复分页列表 
		
		//增加隔行变色效果
  	     $(".listtable").zebra();
  	     
  	   $("#knowledgeDescDiv").mCustomScrollbar({ 
			theme: "light-thick",
			scrollInertia:0,
			autoDraggerLength:true,
			scrollButtons:{
				enable:false
			}
		});
  	   
  	  $("#solutionDiv").mCustomScrollbar({     
			theme: "light-thick",
			scrollInertia:0,
			autoDraggerLength:true,
			scrollButtons:{
				enable:false
			}
		});
});

function submitReply(){
	var ff = $("#evaluateScore").val();
	var cc = $("#replyContentArea").val();
	if(ff=="0" || ff==""){ 
		$.messager.alert('提示', "请先评分!");
		return;
	}
	if($.trim(cc)==""){
		$.messager.alert('提示', "评论内容不能为空!");
		return;
	} 
	if(cc.length>100){
		$.messager.alert('提示', "评论内容不能超过100字符!");
		return;
	}
	var imagStar_empty = ctx+'/dqm/knowledgebase/images/star_empty.gif';
	$.ajax({
		url:ctx+"/knowledgebase/knowlegeReplyAction!addKnowledgeReply.action",
		type:"post",
		data:{evaluate:$("#evaluateScore").val(),replyCotent:$("#replyContentArea").val(),knowledgeId:$("#knowledgeId").val()},
		dataType:"json",
		error: function(){alert('请求超时，请稍候再试');},
		success: function(result){
			$("#replyContentArea").val(""); 
			showGridList({rows:4,knowledgeId:$("#knowledgeId").val()});
			$("#evaluateScore").val("0");
			$(".star-control li").each(function(index,value){
				$(this).removeClass("star-hover");
				$(this).removeClass("star-on"); 
			});
		}
	});
}

function showGridList(data){
	$("#pageNavigationDetail").pager({
		display : 8,			  //最多显示多少页	
		data:data,           //rows 每页显示多少条数
		showDetail:true,
		url: ctx+"/knowledgebase/knowlegeReplyAction!toListKnowledgeReply.action",
		onResult : function(data){  
			var s = new StringBuffer();
			if(data!=null){
				$.each(data,function(index,value){ 
					var picPath = ctx + '/images/headpicture/none.gif';
					if(value.picPath && $.trim(value.picPath)!=''){
						picPath = value.picPath;
					}  
					s.append("<dt><span class='fr'>").append(value.replyTime).append("</span><img src='").append(picPath).append("'/><span>").append(value.replyUserName).append("</span></dt>");
					s.append("<dd>").append(value.replyCotent).append("</dd>");
				}); 
			}else{ 
				s.append("<div style='padding-top:70px;height:180px;hidden;text-align:center;'><img src='").append(ctx).append("/dqm/knowledgebase/images/wushuju.png'/></div>");
			}
			$("#replyContent").html(s.toString());
			
			
			$("#replyContent").mCustomScrollbar("destroy"); 
			$("#replyContent").mCustomScrollbar({ 
				theme: "light-thick",
				scrollInertia:0,
				autoDraggerLength:true,
				scrollButtons:{
					enable:false
				}
			}); 
			
			//$("div.mCSB_dragger").css("height","200px"); 
       }   
	}); 
}

//显示附件列表"bussType":"1" 1代表是知识库业务
function initAttachment(numFilesUploaded) {
		//刷新页面  problemmgr
		$('#table_datagrid').datagrid({
			url:ctx+'/upload/fileAction!toListUploadFiles.action',
			queryParams:{
				"bussId" : $("#knowledgeId").val(),
				"bussType":"1"	
			},
			fit:true,
			border:false,
			fitColumns:true,
			pagination:false,
			pageList:[10,20,30],
			singleSelect:true,
			rownumbers:false,
			sortName:'uploadTime',
			/* pagePosition:'both', */
			autoRowHeight:true,
			columns:[[{
				field:'fileName',
				title:'附件名称',
				width:250
			},{
				field:'uploadUserName',
				title:'上传人',
				width:60
			   },{
				field:'fileSize',
				title:'附件大小',
				width:60
			   },{
				field:'uploadTime',
				title:'上传时间',
				width:150
			},{
				field:'fileId',
				title:'操作',
				width:60,  
				align:'center', formatter: function (fileId,rowData,rowIndex){ 
					return '<span  style="cursor:pointer" onclick="downLoadFile(\''+fileId+'\')" )"><img onclick="downLoadFile(\''+fileId+'\')" src="'+ctx+'/images/icons/downFile.png" title="下载" alt="下载"/>下载</span>';
				}
			}]],
		}); 
	}
//附件下载
function downLoadFile(fileId){
	$("#fileDownFrame").attr("src",ctx+"/upload/fileAction!toDownLoadFile.action?fileId="+fileId);
}
